package com.ruoyi.statistics.service.impl;


import com.ruoyi.statistics.domain.Amount;
import com.ruoyi.statistics.domain.Survey;

import com.ruoyi.statistics.domain.SurveyData;
import com.ruoyi.statistics.mapper.SysStatisticsSurveyMapper;
import com.ruoyi.statistics.service.ISysStatisticsSurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;


@Service
public class SysStatisticsSurveyServiceImpl implements ISysStatisticsSurveyService {
    @Autowired
    private SysStatisticsSurveyMapper sysStatisticsSurveyMapper;

    @Override
    public List<Survey> getAllStatisticsSurvey(Date startTime, Date endTime) {
        List<Survey> result = new ArrayList<>();
        Date currentDate = new Date(startTime.getTime());
        while (!currentDate.after(endTime)) {
            List<SurveyData> surveyData = sysStatisticsSurveyMapper.getSurveyDatesByDate(currentDate);

            // 构造Survey对象
            Survey survey = new Survey();
            survey.setDate(currentDate);
            survey.setSurveyData(surveyData);

            result.add(survey);

            // 日期加1天
            currentDate = new Date(currentDate.getTime() + TimeUnit.DAYS.toMillis(1));
        }
        return result;
    }

    @Override
    public List<Survey> getStoreStatisticsSurvey(Date startTime, Date endTime, Long deptId) {
        List<Survey> result = new ArrayList<>();
        Date currentDate = new Date(startTime.getTime());
        while (!currentDate.after(endTime)) {
            List<SurveyData> surveyData = sysStatisticsSurveyMapper.getStoreSurveyDatesByDate(currentDate,deptId);

            // 构造Survey对象
            Survey survey = new Survey();
            survey.setDate(currentDate);
            survey.setSurveyData(surveyData);

            result.add(survey);

            // 日期加1天
            currentDate = new Date(currentDate.getTime() + TimeUnit.DAYS.toMillis(1));
        }
        return result;
    }
}
